#include <iostream>
#include <stdio.h>

using namespace std;

struct Node
{
    int data;
    Node *next;
};

int main()
{
    Node *p, *r;
    Node *head = new Node;
    Node *tail = head;

    int n, q;
    cin >> n;
    cin >> q;
    for (int i = 0; i < n; i++)
    {
        p = new Node;
        cin >> p->data;
        p->next = NULL;
        tail->next = p;
        tail = p;
    }

    for (int i = 0; i < q; i++)
    {
        int k, h;
        r = new Node;
        cin >> k >> h;
        for (p = head->next; p->data != k; p = p->next);
        r->data = h;
        
        r->next = p->next;
        p->next = r;
    }
    for (p = head->next; p != NULL; p = p->next)
    {
        cout << p->data << ' ';
    }
    return 0;
}